#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
#include<sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define FIFO_NAME "myfifo"

int main()
{
    char buffer[1024];
    if(mkfifo(FIFO_NAME,0666)<0)
    {
        perror("failed to create fifo");
        exit(1);
    }
    int rfd = open(FIFO_NAME,O_RDONLY);
    if(rfd<0)
    {
        perror("open fail");
        exit(2);
    }
    while(true)
    {
        buf[0]=0;
        printf("Please wait communicate messages...\n");
        ssize_t n = read(rfd,buffer,sizeof(buffer)-1);
        
        if(n>0)
        {
            printf("get client messages:%s",buffer);
        }
        else if(n==0)
        {
            printf("read pipe&&file done\n");
            break;
        }
        else
        {
            break;
        }
    }
    close(rfd);
    return 0;
}